# -*- coding: utf-8 -*-
# 给定一个排序链表，删除所有重复的元素，使得每个元素只出现一次
# 示例 1:
# 输入: 1->1->2
# 输出: 1->2

# 示例 2:
# 输入: 1->1->2->3->3
# 输出: 1->2->3

class ListNode(object):
    def __init__(self, x):
        self.val = x
        self.next = None

def build_list(param):
    if not param:
        return None;
    rtn = ListNode(param[0]);

    node = rtn;
    for i in range(1, len(param)):
        node.next = ListNode(param[i]);
        node = node.next;

    return rtn;

def print_list(head):
    log = "";
    node = head;
    while node:
        log += str(node.val) + " ";
        node = node.next;
    print log;

class Solution(object):
    def deleteDuplicates(self, head):
        """
        :type head: ListNode
        :rtype: ListNode
        """
        last = None;
        current = head;
        while current:
            if last and current.val == last.val:
                last.next = current.next;
            else:
                last = current;
            current = current.next;
        return head;


head = build_list([1,1,2,3,3]);
t = Solution();
print_list(t.deleteDuplicates(head));